#ifndef NET_H
#define NET_H

#include <QWidget>
#include <QStyleOption>
#include <QPaintEvent>
#include <QPainter>
#include <QSerialPort>
#include <QThread>
#include <QDebug>
#include <QtMqtt/qmqttclient.h>
#include <QByteArray>
#include <QtCore>
#include <QMessageBox>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QPushButton>
#include <QLabel>
#include <QDateTime>
#include <QTimer>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include "switchbuttom.h"
#include "stdlib.h"
namespace Ui {
class net;
}
class onenectdata
{
public:
    explicit onenectdata(QWidget *parent = nullptr);
    int temp;
    int humility;
    int sun;

};
class net : public QWidget
{
    Q_OBJECT

public:
    explicit net(QWidget *parent = nullptr);
    ~net();

    bool ESP8266_SendCmd(QByteArray str, QString res);
    void Sleep(int msec);
    onenectdata onenetdata;
    void connectsucceed();
    void disconnectonenent();
    void jsonreceive(QByteArray data);
    void json_status(QJsonObject jsonobj);
    void sundatasu03t();
   // void onenetpublic();
public slots:
     void readPort();
private slots:


    void connectto_clicked();
    void led_clicked(bool ledstatus);
    void mqttreceive(const QByteArray &ba,const QMqttTopicName &topic);
    //void updateTime();
    void slot_timeout(void);
    void su03treadPort();
protected:
     virtual void paintEvent(QPaintEvent *event) override;

private:

    Ui::net *ui;
    QSerialPort *serial;
    QSerialPort *su03t;
    QMqttClient * client;
    QString buffer;
    QJsonDocument jsonDoc;
    QJsonObject jsonobj;
    int flag;
    QString res;
    QString topic="$sys/a8Ifqm939M/device/thing/property/post";
    QString subtopic="$sys/a8Ifqm939M/device/thing/property/set";
    switchbuttom*switchbutton;
    QVBoxLayout*vmainbox;
    QLabel *onenetstatus;
    QPushButton *connectto;
    QLabel*temptext;
    QLabel*humtext;
     QLabel*suntext;
    QLabel*timelabel;
    QLabel*datelabel;
    QHBoxLayout*Hbox;
    bool led_status=false;
    QTimer* my_timer;
    QWidget *widget[10];
    char msg[50];
    char sunsu03t[2];

    // QByteArray msg[5]={0xAA,0x55,0x0,0x55,0xAA};

    void layoutInit();
};


#endif // NET_H
